# compiler
CXX ?= g++ 

# debug or release
DEBUG ?= 1
ifeq ($(DEBUG), 1)
	CXXFLAGS += -g
else
	CXXFLAGS += -O2
endif

CXXFLAGS += -std=c++17

OUTPUT_DIR := bin
TARGET := $(OUTPUT_DIR)/main

all: $(TARGET)

THIRD_PARTY_BUILD := build_3rdparty

THIRD_PARTY_DIR :=../../3rdparty
LOG_LIB_DIR := $(THIRD_PARTY_DIR)/spdlog
LOG_LIB_NAME := spdlog

TEST_LIB_DIR := $(THIRD_PARTY_DIR)/catch2/build/src
TEST_LIB_NAME := Catch2
TEST_LIB_INCLUDE_DIR := $(THIRD_PARTY_DIR)/catch2/src

SERVER_LIB_DIR := ../../bin
SERVER_LIB_NAME := zhserver
SERVER_INCLUDE_DIR := ../

CXXFLAGS += -L$(LOG_LIB_DIR)
CXXFLAGS += -l$(LOG_LIB_NAME)
CXXFLAGS += -lpthread
CXXFLAGS += -I$(LOG_LIB_DIR)/include

CXXFLAGS += -L$(TEST_LIB_DIR)
CXXFLAGS += -l$(TEST_LIB_NAME)
CXXFLAGS += -I$(TEST_LIB_INCLUDE_DIR)
CXXFLAGS += -I$(TEST_LIB_INCLUDE_DIR)/catch2


CXXFLAGS += -L$(SERVER_LIB_DIR)
CXXFLAGS += -l$(SERVER_LIB_NAME)
CXXFLAGS += -I$(SERVER_INCLUDE_DIR)

SOURCES := main.cpp \
		test_catch2.cpp \
		test_logger.cpp\
		test_parse_http_post.cpp\
		test_timer.cpp\
		test_buffer.cpp\
		test_smart_ptr.cpp\

$(TARGET): $(SOURCES) | $(THIRD_PARTY_BUILD) $(OUTPUT_DIR)
		   $(CXX) -o $(TARGET) $^ $(CXXFLAGS)
		
$(THIRD_PARTY_BUILD):
	@echo "Tip: Please make sure you have executed build_3rdparty.sh before."
	

$(OUTPUT_DIR):
	mkdir $(OUTPUT_DIR)

clean:
	rm -rf $(OUTPUT_DIR)
# cd 3rdparty/spdlog && make clean && git clean -fd


